﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Facade;
using IronOne.SalesOne.BusinessObjects;


namespace IronOne.SalesOne.SalesOneWeb.ContactManagement
{
    public partial class ClientDetails : SOSecurityPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string type = string.Empty;

                if (!string.IsNullOrEmpty(Request.QueryString["t"]))
                {
                    type = Request.QueryString["t"];
                }

                if (type == "p")
                {
                    btnPolicy.Visible = true;
                }
                else
                {
                    btnPolicy.Visible = false;
                }

                ValidateUserCredentials(Request.Url.LocalPath);

                if (!IsPostBack)
                {
                    if (!string.IsNullOrEmpty(Request.UrlReferrer.ToString()))
                    {
                        ViewState["refUrl"] = Request.UrlReferrer.ToString();
                    }

                }

                if (Session["client"] != null)
                {
                    Customer cus = (Customer)Session["client"];

                    lblClientId.Text = cus.CustomerId.ToString();
                    lblName.Text = cus.Title + " " + cus.FirstName + " " + cus.LastName;
                    lblOtherName.Text = cus.LastName;
                    lblId.Text = cus.IdType + "-" + cus.IdNumber;
                    lblDob.Text = cus.DOB;
                    lblGender.Text = cus.Gender;
                    lblMarital.Text = cus.MaritalStatus;
                    lblProfession.Text = cus.Profession;
                    lblHomeAddress1.Text = cus.Address1;
                    lblHomeAddress2.Text = cus.Address2;
                    lblHomePhone.Text = cus.HomeTelephone;
                    lblOfficePhone.Text = cus.OfficialTelephone;
                    lblCity.Text = cus.City;
                    lblState.Text = cus.State;
                    lblEmail.Text = cus.EMail;
                    lblCountry.Text = cus.Country;

                    Session.Remove("client");

                }
            }
            catch (Exception)
            {
               
            }
            

        }

        protected void cancelButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(Request.QueryString["t"]))
                {
                    if (Request.QueryString["t"] == "p")
                    {
                        Response.Redirect("~/ContactManagement/SearchContact.aspx");
                    }

                }
                else
                {
                    Response.Redirect(ViewState["refUrl"].ToString());
                }
            }
            catch (Exception)
            {
                
            }
           
            
        }

        protected void btnPolicy_Click(object sender, EventArgs e)
        {
            //Response.Redirect("");
            Response.Redirect("~/ContactManagement/ShowPolicies.aspx?cl=" + lblClientId.Text);
        }
    }
}
